<?php
class Page extends PageBaseUpdate {

	public function InitializeComponent(){
		parent::InitializeComponent();
		$this->ClassName = "Usuario";
		$this->LocalControls = "Nombrecompleto,Username,Documento,Direccion,Email,Idrol";
	}
	public function onLoad($param){
		parent::onLoad($param);
		if(!$this->IsPostBack){
			$id = $this->Request["id"];
			if(!is_null($id)){//es un Update
				$this->lblPassword->Visible=false;
				$this->Password->Visible=false;
				$this->rfv_Password->Enabled=false;
			}
		}
	}

	protected function btnAceptar_OnClick($sender, $param){
			$id = $this->Request["id"];
			if(!is_null($id)){//es un Update
					$this->Save();
			}else{//nuevo registro
					$oUsuario=new Usuario();
					$oUsuario->setNombrecompleto($this->Nombrecompleto->Text);
					$oUsuario->setUsername($this->Username->Text);
					$oUsuario->setDocumento($this->Documento->Text);
					$oUsuario->setDireccion($this->Direccion->Text);
					$oUsuario->setEmail($this->Email->Text);
					$oUsuario->setIdrol($this->Idrol->SelectedValue);
					$oUsuario->setPassword($this->Password->Text);
					$oUsuario->Save();
			}

			$this->Back("?page=Usuario.Home");
	}

	public function btnCancelar_OnClick($sender, $param){
		$this->Back("?page=Usuario.Home");
	}

	public function LoadDataRelated(){
		$valueFirst = "0";
		$textFirst = "Seleccione";
		$this->Idrol->DataValueField    =  "IDROL";
		$this->Idrol->DataTextField     =  "NOMBRE";
		$this->Idrol->PromptValue       =   $valueFirst;
		$this->Idrol->PromptText        =   $textFirst;
		$this->Idrol->DataSource        =   RolPeer::GetRoles();
		$this->Idrol->dataBind();
	}
}
?>